﻿using System;

namespace Pharma
{
    class Sales
    {
        public int medicineCode;
        public int quantitySold;
        public int plannedSales;
        public int actualSales;
        public string region;

        public bool Accept()
        {
            int temp = 0;
            int quantityOnHd=0;
             LB:
                try
                {
                    Console.Write("Enter the Medicine Code:");
                    medicineCode = Convert.ToInt32(Console.ReadLine());
                    if (medicineCode <= 0)
                    {
                        Console.WriteLine("Medicine Code <= 0");
                        goto LB;
                    }

                    foreach (var item in Test.md.list)
                    {
                        if (item.medicineCode == medicineCode)
                        {
                            temp = 1;
                            quantityOnHd = item.quantityOnHand;
                            Test.md.Refresh(medicineCode);
                        }
                    }
                    if (temp == 0)
                    {
                        Console.WriteLine("Can not found Medicine Code");
                        goto LB;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    goto LB;
                }
             LB1:
                try
                {
                    Console.Write("Enter the Quantity Sold:");
                    quantitySold = Convert.ToInt32(Console.ReadLine());
                    if (quantitySold <= 0 || quantitySold > quantityOnHd)
                    {
                        Console.WriteLine("Number records Quantity Sold <= 0 or > Quantity On Hand");
                        goto LB1;
                    }
                    foreach (var item in Test.md.list)
                    {
                        if (item.medicineCode == medicineCode)
                        {
                            item.quantityOnHand -= quantitySold;
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    goto LB1;
                }
             LB2:
                 try
                 {
                     Console.Write("Enter the Planned Sales:");
                     plannedSales = Convert.ToInt32(Console.ReadLine());
                     if (plannedSales <= 0)
                     {
                         Console.WriteLine("Number records Planned Sales <= 0");
                         goto LB2;
                     }
                 }
                 catch (Exception e)
                 {
                     Console.WriteLine(e.Message);
                     goto LB2;
                 }
             LB3:
                 try
                 {
                     Console.Write("Enter the Actual Sales:");
                     actualSales = Convert.ToInt32(Console.ReadLine());
                     if (actualSales <= 0)
                     {
                         Console.WriteLine("Number records Actual Sales <= 0");
                         goto LB3;
                     }
                 }
                 catch (Exception e)
                 {
                     Console.WriteLine(e.Message);
                     goto LB3;
                 } 
                 Console.Write("Enter the Region:");
                 region = Console.ReadLine();
                 return true;
        }
        public void Display()
        {
            Console.WriteLine("Medicine Code: " + medicineCode);
            Console.WriteLine("Quantity Sold " + quantitySold);
            Console.WriteLine("Planned Sales: " + plannedSales);
            Console.WriteLine("Actual Sales: " + actualSales);
            Console.WriteLine("Region: " + region);
        }

    }
}
